package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {


    void insert(Orders orders);

    @Select("select * from orders where number = #{number}")
    Orders getByNumber(String number);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    Page<OrderVO> historyOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    OrderVO getById(Long id);

    //获取未支付且未取消的订单
    @Select("select * from orders where status = 1 and pay_status = 0")
    List<Orders> getUnpaidOrders();

    //获取还在派送中的订单
    @Select("select * from orders where status = 4")
    List<Orders> getDeliveredOrders();

    List<Orders> turnoverStatistics(LocalDateTime begin, LocalDateTime end);

    @Select("select * from orders where order_time >=#{begin} and order_time<=#{end} and status>4")
    List<Orders> finALlInTime(LocalDateTime begin, LocalDateTime end);

    @Select("select * from orders where order_time >= #{begin} and order_time<= #{end}")
    List<Orders> getByTime(LocalDateTime begin, LocalDateTime end);


}
